
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>docker19 构建自己的centos · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="docker20 发布镜像.html" />
    
    
    <link rel="prev" href="docker18 dockerFile基本命令.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="docker01 docker能干嘛.html">
            
                <a href="docker01 docker能干嘛.html">
            
                    
                    docker01 docker能干嘛
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="docker02 安装docker.html">
            
                <a href="docker02 安装docker.html">
            
                    
                    docker02 安装docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="docker03 docker原理.html">
            
                <a href="docker03 docker原理.html">
            
                    
                    docker03 docker原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="docker04 镜像基本命令.html">
            
                <a href="docker04 镜像基本命令.html">
            
                    
                    docker04 镜像基本命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="docker05 容器基本命令.html">
            
                <a href="docker05 容器基本命令.html">
            
                    
                    docker05 容器基本命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="docker06 常用其他命令.html">
            
                <a href="docker06 常用其他命令.html">
            
                    
                    docker06 常用其他命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="docker07 进入当前正在运行的容器.html">
            
                <a href="docker07 进入当前正在运行的容器.html">
            
                    
                    docker07 进入当前正在运行的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="docker08 部署nginx.html">
            
                <a href="docker08 部署nginx.html">
            
                    
                    docker08 部署nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="docker09 部署tomcat.html">
            
                <a href="docker09 部署tomcat.html">
            
                    
                    docker09 部署tomcat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="docker10 可视化面板.html">
            
                <a href="docker10 可视化面板.html">
            
                    
                    docker10 可视化面板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="docker11 镜像原理.html">
            
                <a href="docker11 镜像原理.html">
            
                    
                    docker11 镜像原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="docker12 commit镜像.html">
            
                <a href="docker12 commit镜像.html">
            
                    
                    docker12 commit镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="docker13 容器数据卷.html">
            
                <a href="docker13 容器数据卷.html">
            
                    
                    docker13 容器数据卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="docker14 具名挂载和匿名挂载.html">
            
                <a href="docker14 具名挂载和匿名挂载.html">
            
                    
                    docker14 具名挂载和匿名挂载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="docker15 初始dockerfile.html">
            
                <a href="docker15 初始dockerfile.html">
            
                    
                    docker15 初始dockerfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="docker16 数据卷容器.html">
            
                <a href="docker16 数据卷容器.html">
            
                    
                    docker16 数据卷容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="docker17 dockerFile.html">
            
                <a href="docker17 dockerFile.html">
            
                    
                    docker17 dockerFile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="docker18 dockerFile基本命令.html">
            
                <a href="docker18 dockerFile基本命令.html">
            
                    
                    docker18 dockerFile基本命令
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.20" data-path="docker19 构建自己的centos.html">
            
                <a href="docker19 构建自己的centos.html">
            
                    
                    docker19 构建自己的centos
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="docker20 发布镜像.html">
            
                <a href="docker20 发布镜像.html">
            
                    
                    docker20 发布镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="docker21 网络详情.html">
            
                <a href="docker21 网络详情.html">
            
                    
                    docker21 网络详情
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="docker22 容器互联.html">
            
                <a href="docker22 容器互联.html">
            
                    
                    docker22 容器互联
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="docker23 自定义网络.html">
            
                <a href="docker23 自定义网络.html">
            
                    
                    docker23 自定义网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="docker24 SpringBoot 微服务打包Docker镜像.html">
            
                <a href="docker24 SpringBoot 微服务打包Docker镜像.html">
            
                    
                    docker24 SpringBoot 微服务打包Docker镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="docker25 dockerFile_demo.html">
            
                <a href="docker25 dockerFile_demo.html">
            
                    
                    docker25 dockerFile_demo
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >docker19 构建自己的centos</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="&#x5B9E;&#x6218;&#x6D4B;&#x8BD5;">&#x5B9E;&#x6218;&#x6D4B;&#x8BD5;</h3>
<p>&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos</p>
<pre><code class="lang-bash"><span class="hljs-comment"># &#x7F16;&#x5199;dockerfile&#x914D;&#x7F6E;&#x6587;&#x4EF6;</span>
[root@iz8g9301trfnpxz ~]<span class="hljs-comment"># cd /home</span>
[root@iz8g9301trfnpxz home]<span class="hljs-comment"># mkdir dockerfile</span>
[root@iz8g9301trfnpxz home]<span class="hljs-comment"># ls</span>
admin  ceshi  dockerfile  docker-test-volume  kuangshen.java  mysql  test.java
[root@iz8g9301trfnpxz home]<span class="hljs-comment"># cd dockerfile/</span>
[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># ls</span>
[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># vim mydocker-centos</span>
[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># cat mydocker-centos </span>
FROM centos
MAINTAINER victor&lt;510510280@qq.com&gt;

ENV MYPATH /urs/<span class="hljs-built_in">local</span>
WORKDIR <span class="hljs-variable">$MYPATH</span>

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD <span class="hljs-built_in">echo</span> <span class="hljs-variable">$MYPATH</span>
CMD <span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;-------------------end------------------&quot;</span>
CMD /bin/bash


<span class="hljs-comment"># &#x901A;&#x8FC7;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x6784;&#x5EFA;&#x955C;&#x50CF;</span>
</code></pre>
<p><strong>&#x547D;&#x4EE4; docker build -f dockerfile &#x6587;&#x4EF6;&#x8DEF;&#x5F84; -t &#x955C;&#x50CF;&#x540D;</strong></p>
<pre><code class="lang-bash">[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># docker build -f mydocker-centos -t mycentos:0.1 .</span>
Sending build context to Docker daemon  2.048kB
Step 1/10 : FROM centos
 ---&gt; 831691599b88
Step 2/10 : MAINTAINER victor&lt;510510280@qq.com&gt;
 ---&gt; Running <span class="hljs-keyword">in</span> 5485ccbf2672
Removing intermediate container 5485ccbf2672
 ---&gt; 131330e2008d
Step 3/10 : ENV MYPATH /urs/<span class="hljs-built_in">local</span>
 ---&gt; Running <span class="hljs-keyword">in</span> 7ddbc3982cdc
Removing intermediate container 7ddbc3982cdc
 ---&gt; d8afdf73ae5e
Step 4/10 : WORKDIR <span class="hljs-variable">$MYPATH</span>
 ---&gt; Running <span class="hljs-keyword">in</span> ee1bb41513bc
Removing intermediate container ee1bb41513bc
 ---&gt; 77b75be518d6
Step 5/10 : RUN yum -y install vim
 ---&gt; Running <span class="hljs-keyword">in</span> 4d801fad886d
CentOS-8 - AppStream                            409 kB/s | 5.8 MB     00:14    
CentOS-8 - Base                                 2.5 MB/s | 2.2 MB     00:00    
CentOS-8 - Extras                               941  B/s | 7.0 kB     00:07    
Dependencies resolved.
================================================================================
 Package             Arch        Version                   Repository      Size
================================================================================
Installing:
 vim-enhanced        x86_64      2:8.0.1763-13.el8         AppStream      1.4 M
Installing dependencies:
 gpm-libs            x86_64      1.20.7-15.el8             AppStream       39 k
 vim-common          x86_64      2:8.0.1763-13.el8         AppStream      6.3 M
 vim-filesystem      noarch      2:8.0.1763-13.el8         AppStream       48 k
 <span class="hljs-built_in">which</span>               x86_64      2.21-12.el8               BaseOS          49 k

Transaction Summary
================================================================================
Install  5 Packages

Total download size: 7.8 M
Installed size: 31 M
Downloading Packages:
(1/5): gpm-libs-1.20.7-15.el8.x86_64.rpm        219 kB/s |  39 kB     00:00    
(2/5): vim-filesystem-8.0.1763-13.el8.noarch.rp 434 kB/s |  48 kB     00:00    
(3/5): <span class="hljs-built_in">which</span>-2.21-12.el8.x86_64.rpm             2.5 MB/s |  49 kB     00:00    
(4/5): vim-enhanced-8.0.1763-13.el8.x86_64.rpm  813 kB/s | 1.4 MB     00:01    
(5/5): vim-common-8.0.1763-13.el8.x86_64.rpm    839 kB/s | 6.3 MB     00:07    
--------------------------------------------------------------------------------
Total                                           805 kB/s | 7.8 MB     00:09     
warning: /var/cache/dnf/AppStream-02e86d1c976ab532/packages/gpm-libs-1.20.7-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream                            862 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : <span class="hljs-string">&quot;CentOS (CentOS Official Signing Key) &lt;security@centos.org&gt;&quot;</span>
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction <span class="hljs-built_in">test</span>
Transaction <span class="hljs-built_in">test</span> succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : <span class="hljs-built_in">which</span>-2.21-12.el8.x86_64                               1/5 
  Installing       : vim-filesystem-2:8.0.1763-13.el8.noarch                2/5 
  Installing       : vim-common-2:8.0.1763-13.el8.x86_64                    3/5 
  Installing       : gpm-libs-1.20.7-15.el8.x86_64                          4/5 
  Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64                          4/5 
  Installing       : vim-enhanced-2:8.0.1763-13.el8.x86_64                  5/5 
  Running scriptlet: vim-enhanced-2:8.0.1763-13.el8.x86_64                  5/5 
  Running scriptlet: vim-common-2:8.0.1763-13.el8.x86_64                    5/5 
  Verifying        : gpm-libs-1.20.7-15.el8.x86_64                          1/5 
  Verifying        : vim-common-2:8.0.1763-13.el8.x86_64                    2/5 
  Verifying        : vim-enhanced-2:8.0.1763-13.el8.x86_64                  3/5 
  Verifying        : vim-filesystem-2:8.0.1763-13.el8.noarch                4/5 
  Verifying        : <span class="hljs-built_in">which</span>-2.21-12.el8.x86_64                               5/5 

Installed:
  gpm-libs-1.20.7-15.el8.x86_64         vim-common-2:8.0.1763-13.el8.x86_64    
  vim-enhanced-2:8.0.1763-13.el8.x86_64 vim-filesystem-2:8.0.1763-13.el8.noarch
  <span class="hljs-built_in">which</span>-2.21-12.el8.x86_64             

Complete!
Removing intermediate container 4d801fad886d
 ---&gt; 9458be1e73c5
Step 6/10 : RUN yum -y install net-tools
 ---&gt; Running <span class="hljs-keyword">in</span> c764b7488e52
Last metadata expiration check: 0:00:17 ago on Fri Jul 31 06:20:50 2020.
Dependencies resolved.
================================================================================
 Package         Architecture Version                        Repository    Size
================================================================================
Installing:
 net-tools       x86_64       2.0-0.51.20160912git.el8       BaseOS       323 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 323 k
Installed size: 1.0 M
Downloading Packages:
net-tools-2.0-0.51.20160912git.el8.x86_64.rpm   3.4 MB/s | 323 kB     00:00    
--------------------------------------------------------------------------------
Total                                           208 kB/s | 323 kB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction <span class="hljs-built_in">test</span>
Transaction <span class="hljs-built_in">test</span> succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1 
  Running scriptlet: net-tools-2.0-0.51.20160912git.el8.x86_64              1/1 
  Verifying        : net-tools-2.0-0.51.20160912git.el8.x86_64              1/1 

Installed:
  net-tools-2.0-0.51.20160912git.el8.x86_64                                     

Complete!
Removing intermediate container c764b7488e52
 ---&gt; 7e388732db7d
Step 7/10 : EXPOSE 80
 ---&gt; Running <span class="hljs-keyword">in</span> 3805ab7a1061
Removing intermediate container 3805ab7a1061
 ---&gt; de64af90d6a6
Step 8/10 : CMD <span class="hljs-built_in">echo</span> <span class="hljs-variable">$MYPATH</span>
 ---&gt; Running <span class="hljs-keyword">in</span> 30d1c0c9ba45
Removing intermediate container 30d1c0c9ba45
 ---&gt; 0dcdb63da784
Step 9/10 : CMD <span class="hljs-built_in">echo</span> <span class="hljs-string">&quot;-------------------end------------------&quot;</span>
 ---&gt; Running <span class="hljs-keyword">in</span> 5ea7cbe4f0c7
Removing intermediate container 5ea7cbe4f0c7
 ---&gt; 146bc756b80a
Step 10/10 : CMD /bin/bash
 ---&gt; Running <span class="hljs-keyword">in</span> 537d8346e6be
Removing intermediate container 537d8346e6be
 ---&gt; 3f4f73543aa2
Successfully built 3f4f73543aa2
Successfully tagged mycentos:0.1
[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment">#</span>
</code></pre>
<p><strong>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x5C31;&#x53EF;&#x4EE5;&#x7528;&#x4E86;</strong></p>
<pre><code class="lang-bash">[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># docker images</span>
REPOSITORY            TAG                 IMAGE ID            CREATED              SIZE
mycentos              0.1                 3f4f73543aa2        About a minute ago   287MB
kuangshen/centos      1.0                 5c7e025<span class="hljs-built_in">fc</span>4ff        4 hours ago          215MB
tomcat02              1.0                 b17b415625d5        6 hours ago          657MB
tomcat                latest              9a9ad4f631f8        2 days ago           647MB
portainer/portainer   latest              62771b0b9b09        8 days ago           79.1MB
mysql                 5.7                 8679ced16d20        8 days ago           448MB
nginx                 latest              8cf1bfb43ff5        9 days ago           132MB
redis                 latest              50541622f4f1        9 days ago           104MB
centos                latest              831691599b88        6 weeks ago          215MB
elasticsearch         7.6.2               f29a1ee41030        4 months ago         791MB
elasticsearch         latest              5acf0e8da90b        22 months ago        486MB
[root@iz8g9301trfnpxz dockerfile]<span class="hljs-comment"># docker run -it mycentos:0.1</span>
[root@88886ca9deb0 <span class="hljs-built_in">local</span>]<span class="hljs-comment"># pwd</span>
/urs/<span class="hljs-built_in">local</span>
[root@88886ca9deb0 <span class="hljs-built_in">local</span>]<span class="hljs-comment">#</span>
</code></pre>
<p>&#x9879;&#x76EE;&#x90E8;&#x7F72;&#x6210;&#x529F;,&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8BBF;&#x95EE;ok!</p>
<p>&#x6211;&#x4EEC;&#x4EE5;&#x540E;&#x5F00;&#x53D1;&#x6B65;&#x9AA4;:&#x9700;&#x8981;&#x638C;&#x63E1;Dockerfile &#x6211;&#x4EEC;&#x4EE5;&#x540E;&#x90FD;&#x662F;&#x4F7F;&#x7528;docker&#x955C;&#x50CF;&#x6765;&#x53D1;&#x5E03;&#x7684;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="docker18 dockerFile基本命令.html" class="navigation navigation-prev " aria-label="Previous page: docker18 dockerFile基本命令">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="docker20 发布镜像.html" class="navigation navigation-next " aria-label="Next page: docker20 发布镜像">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"docker19 构建自己的centos","level":"1.20","depth":1,"next":{"title":"docker20 发布镜像","level":"1.21","depth":1,"path":"docker20 发布镜像.md","ref":"docker20 发布镜像.md","articles":[]},"previous":{"title":"docker18 dockerFile基本命令","level":"1.19","depth":1,"path":"docker18 dockerFile基本命令.md","ref":"docker18 dockerFile基本命令.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docker19 构建自己的centos.md","mtime":"2021-04-17T06:21:12.836Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-17T07:50:48.567Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

